package cn.yunhe.action;

import java.util.ArrayList;
import java.util.List;

import cn.yunhe.model.House;
import cn.yunhe.model.SouSuo;
import cn.yunhe.services.HouseServices;
import cn.yunhe.util.BaseAction;
import cn.yunhe.util.PageUtil;

/**
 * 
 * @author Administrator
 *
 */
public class HouseAction extends BaseAction {
	private String title;
	private String area;
	private String street;
	private String type;
	private String floorage;
	private String price;
	//通过id查询住房
	private String id;
	private House house;
	
	private int currPage;
	private int totalPage;
	private String pageIndex;
	private List<House> houseList = new ArrayList<House>();
	private HouseServices hs = new HouseServices();	 

	public String getHouseByTiaoJian() {
		// 获得页数
		if (pageIndex != null && !"".equals(pageIndex)) {
			currPage = Integer.parseInt(pageIndex);
		}
		// 获得数据总数
		int houseCount = hs.getHouseCountByTiaoJian(title, area, street, type, floorage, price, currPage);
		// 获得总页数
		totalPage = PageUtil.pageCount(houseCount, SouSuo.pageCount);
		// 处理首尾页
		if (currPage < 1) {
			currPage = 1;
		} else if (currPage > totalPage) {
			currPage = totalPage;
		}
		houseList = hs.getHouseByTiaoJain(title, area, street, type, floorage, price, currPage);
		return SUCCESS;
	}
	
	
	public String getHouseById(){
		if(id!=null&&!"".equals(id)){
			int houseId = Integer.parseInt(id);
			house = hs.getHouseById(houseId);
			return SUCCESS;
		}
		return ERROR;
	}
	//修改住房信息
	public String delHouse(){
		if(hs.editHouse(house)){
			return SUCCESS;
		}
		return ERROR;
	}
	
	public List<House> getHouseList() {
		return houseList;
	}

	public void setHouseList(List<House> houseList) {
		this.houseList = houseList;
	}

	public HouseServices getHs() {
		return hs;
	}

	public void setHs(HouseServices hs) {
		this.hs = hs;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public String getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(String pageIndex) {
		this.pageIndex = pageIndex;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getFloorage() {
		return floorage;
	}

	public void setFloorage(String floorage) {
		this.floorage = floorage;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public House getHouse() {
		return house;
	}
	public void setHouse(House house) {
		this.house = house;
	}
	
}
